package com.gljx.web.service.impl;

import com.gljx.web.Entity.BigCarData;
import com.gljx.web.Entity.Student;
import com.gljx.web.dao.CommonDao;
import com.gljx.web.dao.StudentMapper;
import com.gljx.web.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
@Transactional
public class StudentServiceImpl extends CommonDao implements StudentService {

    @Autowired
    private StudentMapper studentMapper;

    /**
     * 取分页数据    dmz 20160921
     *
     * @param pindex 页码
     * @param psql   SQL语句，需要带 rownum rn 例如：select rownum rn,t.* from zzda t
     * @param psize  每页记录数
     */
    @Override
    public Map<String, Object> selectPage(int pindex, String psql, int psize) {
        Map<String, Object> paramMap = new HashMap<String, Object>();
        paramMap.put("Pindex", pindex);
        paramMap.put("Psql", psql);
        paramMap.put("Psize", psize);
        paramMap.put("Pcount", oracle.jdbc.OracleTypes.INTEGER);
        paramMap.put("v_cur", oracle.jdbc.OracleTypes.CURSOR);
        this.getSqlSession().select("com.gljx.web.dao.StudentMapper.pagemap", paramMap, null);
        return paramMap;
    }

    /**
     * 取记录总数      dmz 20160921
     *
     * @param psql   SQL语句
     * @param Pcount 记录总数
     * @return
     */
    @Override
    public Map<String, Object> selectPageCount(String psql) {
        Map<String, Object> paramMap = new HashMap<String, Object>();
        paramMap.put("Psql", psql);
        paramMap.put("Pcount", oracle.jdbc.OracleTypes.INTEGER);
        this.getSqlSession().select("com.gljx.web.dao.StudentMapper.pagecount", paramMap, null);
        return paramMap;
    }

	
	/**
	 * 删除学员
	 */
    /**
     * 插入学员记录
     */
    @Override
    public void insertStudent(Student student) {
        // TODO Auto-generated method stub
        studentMapper.insertStudent(student);
    }


	/**
	 * 根据条件查询学员
	 */
	@Override
	public List<Student> selectStudentByCon(Student student, String beginTime, String endTime) {
		// TODO Auto-generated method stub
		Map<String, Object> paramMap = new HashMap<String, Object>();
	       paramMap.put("v_fnameL2", student.getFnameL2());
	       paramMap.put("v_endTime", endTime);
	       paramMap.put("v_beginTime", beginTime);
	       paramMap.put("v_cfidcardno", student.getCfidcardno());
	       paramMap.put("v_cfsjhm", student.getCfsjhm());
	       paramMap.put("v_cur", oracle.jdbc.OracleTypes.CURSOR);
	       this.getSqlSession().select("com.gljx.web.dao.StudentMapper.selectStudentByCon", paramMap, null);
	       return  (List<Student>) paramMap.get("v_cur");
	}

	

    /**
     * 调用存储过程查询学员
     */
    @Override
    public Student selectStudentById(String id) {

        return studentMapper.selectStudentById(id);
    }

    /**
     * 更新学员信息
     */
    @Override
    public int updateStudent(Student student) {
        // TODO Auto-generated method stub
        return studentMapper.updateStudent(student);
    }

    @Override
    public void deteleStudentByFid(String[] fid) {
        // TODO Auto-generated method stub
        studentMapper.deteleStudentByFid(fid);
    }

    /**
     * @Author lcx
     * @Date 2017/11/13 0013 上午 9:05
     * 按照姓名模糊查询学员信息
     */
    @Override
    public List<Student> selectStudentByCfidcardno(String cfidcardno) {
        return studentMapper.selectStudentByCfidcardno(cfidcardno);
    }
    
    /**
     * 审核时更新学员记录
     * @param student
     */
	@Override
	public void updateStudentSelective(Student student) {
		// TODO Auto-generated method stub
		studentMapper.updateByPrimaryKeySelective(student);
	}

	/**
	 * 根据SQL语句查询
	 */
	@Override
	public List<Student> queryStuBySql(String psql) {
		// TODO Auto-generated method stub
		 Map<String, Object> paramMap = new HashMap<String, Object>();
	     paramMap.put("v_psql", psql);
	     paramMap.put("v_cursor", oracle.jdbc.OracleTypes.CURSOR);
	     this.getSqlSession().select("com.gljx.web.dao.StudentMapper.selectStuBySql", paramMap, null);
	     @SuppressWarnings("unchecked")
		List<Student> students =  (List<Student>) paramMap.get("v_cursor");
		return students;
	}

	@Override
	public List<Student> selectStudentByFid(String string) {
		// TODO Auto-generated method stub
		return studentMapper.selectStudentByFid(string);
	}

	
	@Override
	public List<Student> selectStudentByFidTiming(String string) {
		// TODO Auto-generated method stub
		return studentMapper.selectStudentByFidTiming(string);
	}
	
	
	@Override
	public Student selectStudentByCardidAndName(String studentCardId, String name) {
		// TODO Auto-generated method stub
		return studentMapper.selectStudentByCardidAndName(studentCardId, name);
	}

	@Override
	public List<Student> queryStudentByPsql(String psql) {
		// TODO Auto-generated method stub
		return studentMapper.selectStudentByPsql(psql);
	}

	@Override
	public List<BigCarData> selectBigCarData() {
		// TODO Auto-generated method stub
		return studentMapper.selectBigCarData();
	}
	@Override
	public Student selectStudentByDDNO(String ddno) {
		// TODO Auto-generated method stub
		return studentMapper.selectStudentByDDNO(ddno);
	}

	@Override
	public Student queryStudentByIdCardNo(String cerno,String companyId) {
		Map map = new HashMap();
			map.put("cerno",cerno);
			map.put("companyId",companyId);
		// TODO Auto-generated method stub
		return studentMapper.selectStudentByIdCardNo(map);
	}

	@Override
	public Student queryStudentByIdCardNoWx(String cerno) {
		// TODO Auto-generated method stub
		return studentMapper.selectStudentByIdCardNoWx(cerno);
	}

	@Override
	public List<Student> selectTimingStudent(Student student) {
		
		return studentMapper.selectTimingStudent(student);
	}

	@Override
	public List<Student> selectStudentByCfidcardnos(String cfidcardno, String state, String carType,String companyId) {
		Map map = new HashMap();
			map.put("cfidcardno",cfidcardno);
			map.put("companyId",companyId);
			map.put("state",state);
			map.put("carType",carType);
		return studentMapper.selectStudentByCfidcardnos(map);
	}

}
